<template>
  <el-tree
    :data="data"
    node-key="id"
    default-expand-all
    @node-drag-start="handleDragStart"
    @node-drop="handleDrop"
    draggable
    :allow-drop="allowDrop"
    :allow-drag="allowDrag"
    @node-click="showdetail"
  >
  </el-tree>
</template>
<script>
  export default {
    data() {
      return {
        data: [],
        defaultProps: {
          children: "children",
          label: "label",
        },
      };
    },
    props:['allmenu'],
    watch:{
      allmenu:function(oldvalue,value){
        console.log(oldvalue);
        console.log(value);
        this.data = oldvalue
      }  
    },
    methods: {
        showdetail(nodeinfo,parentnode,c){
            console.log(parentnode.parent.data);

            this.$emit('showdetail',nodeinfo,parentnode.parent.data);
        },
        //被拖拽的对象
      handleDragStart(node, ev) {
        console.log("drag start", node);
      },
    //   handleDragEnter(draggingNode, dropNode, ev) {
    //     console.log("tree drag enter: ", dropNode.label);
    //   },
    //   handleDragLeave(draggingNode, dropNode, ev) {
    //     console.log("tree drag leave: ", dropNode.label);
    //   },
    //   handleDragOver(draggingNode, dropNode, ev) {
    //     console.log("tree drag over: ", dropNode.label);
    //   },
    //   handleDragEnd(draggingNode, dropNode, dropType, ev) {
    //     console.log("tree drag end: ", dropNode && dropNode.label, dropType);
    //   },
    //handleDrop的 dropNode dropNode
      handleDrop(draggingNode, dropNode, dropType, ev) {
        console.log("tree drop: ", dropNode.parent, dropType);
        //inner 拖到同级的下一级
        if (dropType == 'inner') {
           console.log('inner情况的获取所在父id：',draggingNode);
           this.$axios.get('/api/menutree/updataFid/'+dropNode.data.id+'/'+draggingNode.data.id).then(res=>{

           }).catch();
        }else{
           console.log('else情况的获取所在fid：',draggingNode);
           this.$axios.get('/api/menutree/updataFid/'+dropNode.data.fid+'/'+draggingNode.data.id).then().catch();

        }
      },
      allowDrop(draggingNode, dropNode, type) {
        if (dropNode.data.label === "二级 3-1") {
          return type !== "inner";
        } else {
          return true;
        }
      },
      allowDrag(draggingNode) {
        return draggingNode.data.label.indexOf("三级 3-2-2") === -1;
      },
    },
  };
</script>